# -*- coding: UTF-8 -*-

# 请求地址，格式如下，不需要写http://

from conf.config import APP_ID, TEMP_ID
from lib.sms.CCPRestSDK import REST

# serverIP = 'app.cloopen.com'
#
# # 请求端口
# serverPort = 8883
#
# # REST版本号
# softVersion = '2013-12-26'
#
#
# def send_sms_by_tpl(to, data, temp_id, app_id):
#     """
#     发送模板短信
#     您的验证码是：{1}，有效期{2}分钟，请勿泄漏给他人。如非本人操作，可不用理会。
#     :param to:手机号码
#     :param data: 内容数据 格式为数组 例如：['12','34']，如不需替换请填 ''
#     :param temp_id:模板Id
#     :param app_id:
#     :return:
#     """
#     # 初始化REST SDK
#     rest = REST(serverIP, serverPort, softVersion)
#     rest.setAccount("8a216da85d7dbf78015d7e4869d100c3", "9aef1cc164bb440b94299ba47dee8a9c")
#     rest.setAppId(app_id)
#     result = rest.sendTemplateSMS(to, data, temp_id)
#     # for k, v in result.items():
#     # if k == 'templateSMS':
#     # for k, s in v.items():
#     #             print('%s:%s' % (k, s))
#     #     else:
#     #         print('%s:%s' % (k, v))
#     return result


_accountSid = '8a216da85d7dbf78015d7e4869d100c3'
_accountToken = '9aef1cc164bb440b94299ba47dee8a9c'

_serverIP = 'app.cloopen.com'

# 请求端口
_serverPort = 8883

# REST版本号
_softVersion = '2013-12-26'

_appId = APP_ID
_tempId = TEMP_ID


class _CCP(object):
    def __init__(self):
        self.rest = REST(_serverIP, _serverPort, _softVersion)
        self.rest.setAccount(_accountSid, _accountToken)
        self.rest.setAppId(_appId)

    @classmethod
    def instance(cls):
        if not hasattr(cls, "_instance"):
            cls._instance = cls()
        return cls._instance

    def sendTemplateSMS(self, to, data, temp_id):
        return self.rest.sendTemplateSMS(to, data, temp_id)


ccp = _CCP.instance()

if __name__ == "__main__":
    # send_sms_by_tpl("15553483801", ['8888', '10'], 194141, "8a216da85d7dbf78015d7e486b6100ca")
    pass
